<template>
	<view class="container">
		<view class="content">
			<uni-list>
				<uni-list-item v-for="(item, index) in list" :key="index" :title="item.flowName" style="margin-top: 5px;" 
				    showArrow rightText="启动" link="navigateTo" :to="`./start?flowId=`+item.flowId+`&flowName=`+item.flowName" @click="onClick" />
			</uni-list>
		</view>
	</view>
</template>

<script>
	import {
		getFlowList,
	} from "@/utils/api/api.js"
	
	export default {
		data() {
			return {
				list: [], // 流程列表
			}
		},
		onShow() {
			uni.$on('refreshData', this.getFlows); // 监听全局事件并执行刷新方法
		},
		onHide() {
			uni.$off('refreshData', this.getFlows); // 页面隐藏时取消监听，避免内存泄漏
		},
		onReady() {
			this.init()
		},
		methods: {
			//第一次调用
			init() {
				this.getFlows();
			},
			getFlows() {
				this.list = [];
				let data = {
					
				}
				getFlowList(data).then(res => {
					if (res.code == 1) {
						res.data.forEach((s) => { // 过滤特殊定制流程
							if (!s["flowName"].startsWith("项目") && !s["flowName"].startsWith("需求") && !s["flowName"].startsWith("问题")){
								this.list.push(s);
							}
						})
					} else {
						uni.showToast({
							title: res.msg,
							duration: 2000,
							mask: true,
							icon: 'none'
						});
					}
				})
			},
		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>
